package com.my.commonlib.util;

import android.content.Context;
import android.content.SharedPreferences;

import com.my.commonlib.BaseApplication;


public class BasePersonSharePreference {
    protected static final String CACHE_TYPE = "person_cache";

    public static final String FORUM_MF_TOKEN = "forum_mf_token";//

    /**
     * 用户的唯一的登录id
     */
    public static void saveStatusBarHeight(int statusHeight) {
        SharedPreferences user_Preferences = BaseApplication.getApp().getSharedPreferences(CACHE_TYPE, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = user_Preferences.edit();
        editor.putInt("StatusBarHeight", statusHeight);
        editor.commit();
    }

    /**
     * 得到当前用户的userID 如果无id则默认返回0
     */
    public static int getStatusBarHeight() {
        try {
            SharedPreferences user_Preferences = BaseApplication.getApp().getSharedPreferences(CACHE_TYPE, Context.MODE_PRIVATE);
            return user_Preferences.getInt("StatusBarHeight", 0);
            // return "8";
        } catch (Exception e) {
            return 0;
        }
    }

    /**
     * 是否登入
     */
    public static void setLogInState(boolean FlagLogIn) {
        SharedPreferences user_Preferences = BaseApplication.getApp().getSharedPreferences(CACHE_TYPE, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = user_Preferences.edit();
        editor.putBoolean("FlagLogIn", FlagLogIn);
        editor.commit();
    }

    private static boolean flag = false;

    /** 得到当前用户的登录状态 */
    public static boolean isLogInState(Context context) {
        try {
            SharedPreferences user_Preferences = BaseApplication.getApp().getSharedPreferences(CACHE_TYPE, Context.MODE_PRIVATE);
            flag = user_Preferences.getBoolean("FlagLogIn", false);
            return flag;
        } catch (Exception e) {
            return false;
        }
    }

    /**
     * 用户的唯一的登录id
     *
     */
    public static void saveUserLogInId(String userid) {
        SharedPreferences user_Preferences = BaseApplication.getApp().getSharedPreferences(CACHE_TYPE, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = user_Preferences.edit();
        editor.putString("LogInId", userid);
        editor.commit();
    }
    /** 得到当前用户的userID 如果无id则默认返回0 */
    public static String getUserLogInId() {
        try {
            SharedPreferences user_Preferences = BaseApplication.getApp().getSharedPreferences(CACHE_TYPE, Context.MODE_PRIVATE);
            return user_Preferences.getString("LogInId", "");
//             return "1005213";
//            return "705822";
        } catch (Exception e) {
            return "";
        }
    }

    /** 保存登录账号*/
    public static void saveLoginName(String loginName){
        SharedPreferences user_Preferences = BaseApplication.getApp().getSharedPreferences(CACHE_TYPE, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = user_Preferences.edit();
        editor.putString("loginName", loginName);
        editor.commit();
    }
    /** 获取登录账号*/
    public static String getLoginName(){
        try {
            SharedPreferences user_Preferences = BaseApplication.getApp().getSharedPreferences(CACHE_TYPE, Context.MODE_PRIVATE);
            return user_Preferences.getString("loginName", "");
        } catch (Exception e) {
            return "";
        }
    }

    public static void saveStr(String str) {
        SharedPreferences user_Preferences = BaseApplication.getApp().getSharedPreferences(CACHE_TYPE, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = user_Preferences.edit();
        editor.putString("use_str", str);
        editor.commit();
    }
    public static String getstr() {
        try {
            SharedPreferences user_Preferences = BaseApplication.getApp().getSharedPreferences(CACHE_TYPE, Context.MODE_PRIVATE);
            return user_Preferences.getString("use_str", "");
        } catch (Exception e) {
            return "";
        }
    }


    /** 保存字符串类型的 数据*/
    public static void setStringMes(String tag,String msg) {
        SharedPreferences pf = BaseApplication.getApp().getSharedPreferences(CACHE_TYPE, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = pf.edit();
        editor.putString(tag, msg);
        editor.commit();
    }
    /** 获取字符串类型的 数据*/
    public static String getStringMes(String tag) {
        try {
            SharedPreferences pf = BaseApplication.getApp().getSharedPreferences(CACHE_TYPE, Context.MODE_PRIVATE);
            return pf.getString(tag, null);
        } catch (Exception e) {
            return null;
        }
    }

    public static void setIntmes(String tag,int msg){
        SharedPreferences pf = BaseApplication.getApp().getSharedPreferences(CACHE_TYPE, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = pf.edit();
        editor.putInt(tag, msg);
        editor.commit();
    }

    public static int getIntmes(String tag){
        try {
            SharedPreferences pf = BaseApplication.getApp().getSharedPreferences(CACHE_TYPE, Context.MODE_PRIVATE);
            return pf.getInt(tag, -1);
        } catch (Exception e) {
            return -1;
        }
    }

    public static void saveLong(String tag,long l_time){
        SharedPreferences pf = BaseApplication.getApp().getSharedPreferences(CACHE_TYPE, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = pf.edit();
        editor.putLong(tag, l_time);
        editor.commit();
    }

    public static long getLong(String tag){
        try {
            SharedPreferences pf = BaseApplication.getApp().getSharedPreferences(CACHE_TYPE, Context.MODE_PRIVATE);
            return pf.getLong(tag, -1);
        } catch (Exception e) {
            return -1;
        }
    }


}
